package config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Slf4j
@Configuration
@RequiredArgsConstructor
public class MqConfig {
    private final RabbitTemplate rabbitTemplate;
    @PostConstruct
    public void init() {
        rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {
            @Override
            public void returnedMessage(ReturnedMessage returned) {
                log.debug("触发return callback!");
                System.out.println("交换机exchange = " + returned.getExchange());
                System.out.println("路由key routingKey = " + returned.getRoutingKey());
                System.out.println("消息message = " + returned.getMessage());
                System.out.println("replyCode = " + returned.getReplyCode());
                System.out.println("replyText = " + returned.getReplyText());
            }
        });
    }
}